package grame;


import java.awt.Color;
import java.util.Random;

public class GameUtils 
{
	public static final String VERSION_NUMBER="1.0.3";
	public static String[] randomGen()
	{
		String random="";
		int length=(int)(Math.random()*5)+3, p=0;
		char[] letters= new char [26];
		char letter='a';
		for(int i=0; i<letters.length; i++)
		{
			letters[i]=letter;
			letter++;
		}
		for(int i=0; i<length; i++)
		{
			p=(int)(Math.random()*26);
			while(!checkLetter(random, letters[p], i))
				p=(int)(Math.random()*26);
			random+=letters[p];
			if(i==0)
				random=random.toUpperCase();
		}
		String[] suffixes=new String[6];
		char[] vowels={'a', 'e', 'i', 'o', 'u'};
		boolean lastVowel=false;
		for(int i=0; i<vowels.length; i++)
			if(random.charAt(random.length()-1)==vowels[i])
				lastVowel=true;
		if(!lastVowel)
			random+=vowels[(int)(Math.random()*5)];
		suffixes[0]="tron";
		suffixes[1]="man";
		suffixes[2]="nar";
		suffixes[3]="ram";
		suffixes[4]="berg";
		suffixes[5]="san";
		random+=suffixes[(int)(Math.random()*6)];
		String[]types=new String[3];
		types[0]="elf";
		types[1]="orc";
		types[2]="human";
		String type=types[(int)(Math.random()*3)];
		int pick=(int)(Math.random()*98);
		if(pick==70)
			random="Meshuly";
		if(pick==10)
			random="Sholiyompompom";
		String[] arr=new String[2];
		arr[0]=random;
		arr[1]=type;
		return arr;
	}
	private static boolean checkLetter(String random, char letter, int i)
	{
		if(i%2==0)
			while((letter!='a')&&(letter!='e')&&(letter!='i')&&(letter!='i')&&(letter!='o')&&(letter!='u'))
				return false;
		if((letter=='q')||(letter=='x')||(letter=='z')||(letter=='u')||(letter=='j'))
			for(int j=0; j<random.length(); j++)
				if(random.toLowerCase().charAt(j)==letter)
					return false;
		if((letter=='o')||(letter=='a'))
		{
			int count=1;
			for(int j=0; j<random.length(); j++)
				if(random.toLowerCase().charAt(j)==letter)
					count++;
			if(count>2)
				return false;
		}
		if((i>0)&&(((letter=='a')||(letter=='e')||(letter=='i')||(letter=='o')||(letter=='u'))&&(random.charAt(i-1)==letter)))
			return false;
		if((i==0)&&(letter=='u'))
			return false;
		return true;
	}
	public static Color randomColor()
	{
		Random r=new Random();
		return new Color(r.nextFloat(), r.nextFloat(), r.nextFloat());
	}
}

